var global_elderId = null;

function elderArrearage_find() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	var searchVal = $('#searchVal').val();
	
	openWaiting('正在查找');
	
	find_basic(path+'/elderArrearage/find', searchVal, function(response) {
		closeWaiting();
		
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				onClickElderArrearageCheckbox:function(todo) {
						var totalPayMoney = 0;
						
						$('ul').each(function() {
							if($(this).find('.magic-checkbox').is(':checked')) {
								var payMoney = $(this).find('.magic-checkbox').attr('arrearageMoney');
								totalPayMoney += payMoney;
							}
						});
						
						$('#payMoney').val(totalPayMoney);
				}
			}
		});
		
		if(response.data.length>0) {
			global_elderId = response.data[0].elderId;
		}
		
		$('#vue_vm_list div').show();
	});
}

function payCost_save() {
	var payWay = parseInt($('input:radio[name="payWay"]:checked').val());
	var payMoney = parseInt($('#payMoney').val());
	var payIdStr = '';
	var payIdArray = [];
	
	$('ul').each(function() {
		if($(this).find('.magic-checkbox').is(':checked')) {
			var payId = $(this).find('.magic-checkbox').attr('id');
			payIdStr += (payIdStr==''? payId: ','+payId);
			payIdArray.push(payId);
		}
	});
	
	var arrearagePayCostForm = {
		payIdList:payIdArray,
		payWay: payWay,
		payMoney: payMoney,
		elderId: global_elderId
	}
	
	save_basic(path+'/elderArrearage/payCost', {arrearagePayCostForm:arrearagePayCostForm}, function() {
		alert('补交成功');
		window.print();
	});
}